package com.zhny.aiot.gd.sfj.plugin;

import com.zhny.aiot.gd.sfj.plugin.device.FertilizerDevice;
import com.zhny.aiot.gd.sfj.plugin.model.FertilizerStoreEntry;
import com.zhny.aiot.plugin.ICenterFacilities;
import com.zhny.aiot.plugin.IDevice;
import com.zhny.aiot.plugin.modbus.ModemServer;
import com.zhny.aiot.plugin.modbus.device.ModemConfig;
import com.zhny.aiot.plugin.modbus.device.ModemDeviceFactory;
import com.zhny.aiot.plugin.modbus.handler.model.ModemRequestMessage;
import com.zhny.aiot.plugin.model.CommandEntry;
import com.zhny.aiot.plugin.model.DeviceEntity;
import com.zhny.aiot.plugin.model.FactoryType;
import com.zhny.aiot.plugin.model.StoreEntity;
import org.pf4j.Extension;
import org.pf4j.Plugin;
import org.pf4j.PluginWrapper;

import java.util.ArrayList;
import java.util.List;

public class FertilizerPlugin extends Plugin {
    public FertilizerPlugin(PluginWrapper wrapper) {
        super (wrapper);
    }
    @Extension
    public static class FertilizerFactory extends ModemDeviceFactory<FertilizerStoreEntry> {
        @Override
        public ModemRequestMessage getRequestMessage(ModemConfig modemConfig) {
            return null;
        }

        @Override
        public IDevice createDevice(ICenterFacilities iCenterFacilities, DeviceEntity entity) {
            return new FertilizerDevice (ModemServer.getInstance ().getEngine () ,this,iCenterFacilities,entity);
        }

        @Override
        public List<CommandEntry> supportCommandClasses(){
            List<CommandEntry> commands = new ArrayList<> ();
            commands.add(CommandEntry.valueOf("openPump", "打开施肥泵", "无参数",null));
            commands.add(CommandEntry.valueOf("closePump", "关闭施肥泵", "无参数",null));
            commands.add(CommandEntry.valueOf("openChannelA", "打开通道A", "无参数",null));
            commands.add(CommandEntry.valueOf("closeChannelA", "关闭通道A", "无参数",null));
            commands.add(CommandEntry.valueOf("openChannelB", "打开通道B", "无参数",null));
            commands.add(CommandEntry.valueOf("closeChannelB", "关闭通道B", "无参数",null));
            commands.add(CommandEntry.valueOf("openChannelC", "打开通道C", "无参数",null));
            commands.add(CommandEntry.valueOf("closeChannelC", "关闭通道C", "无参数",null));
            commands.add(CommandEntry.valueOf("openChannelD", "打开通道D", "无参数",null));
            commands.add(CommandEntry.valueOf("closeChannelD", "关闭通道D", "无参数",null));
            commands.add(CommandEntry.valueOf("openBucketA", "打开搅拌桶A", "无参数",null));
            commands.add(CommandEntry.valueOf("closeBucketA", "关闭搅拌桶A", "无参数",null));
            commands.add(CommandEntry.valueOf("openBucketB", "打开搅拌桶B", "无参数",null));
            commands.add(CommandEntry.valueOf("closeBucketB", "关闭搅拌桶B", "无参数",null));
            commands.add(CommandEntry.valueOf("openBucketC", "打开搅拌桶C", "无参数",null));
            commands.add(CommandEntry.valueOf("closeBucketC", "关闭搅拌桶C", "无参数",null));
            commands.add(CommandEntry.valueOf("openBucketD", "打开搅拌桶D", "无参数",null));
            commands.add(CommandEntry.valueOf("closeBucketD", "关闭搅拌桶D", "无参数",null));
            commands.add(CommandEntry.valueOf("readPumpState", "读取泵状态", "无参数",null));
            commands.add(CommandEntry.valueOf("readMain", "读取PH、EC、压力值", "无参数",null));
            return commands;
        }

        @Override
        public Class<? extends StoreEntity> storeClass() {
            return FertilizerStoreEntry.class;
        }

        @Override
        public String getId() {
            return "gd-sfj-plugin";
        }

        @Override
        public String getName() {
            return "贵大水肥一体机";
        }

        @Override
        public FactoryType getType() {
            return FactoryType.FertilizerController;
        }
    }
}
